#include "addgameobjectcommand.h"
#include "gameObjects/abstractgameobject.h"
#include "document.h"

AddGameObjectCommand::AddGameObjectCommand( QPointer<Document> doc, QPointer<AbstractGameObject> gameObject,
	bool bAdd, QUndoCommand* parent /*= 0*/ )
	: AbstractUndoCommand(parent)
	, m_doc(doc)
	, m_gameObject(gameObject)
	, m_bAdd(bAdd)
{
	if(m_bAdd)
	{
		setText("Add Game Object");
	}
	else
	{
		setText("Remove Game Object");
	}
}

void AddGameObjectCommand::undo()
{
	if(m_bAdd)
	{
		m_doc->removeGameObject(m_gameObject);
	}
	else
	{
		m_doc->addGameObject(m_gameObject);
	}
}

void AddGameObjectCommand::redo()
{
	if(m_bAdd)
	{
		m_doc->addGameObject(m_gameObject);
	}
	else
	{
		m_doc->removeGameObject(m_gameObject);
	}
}
